﻿@using Pyramid.Common
@using Pyramid.Models
@using Pyramid.Mvc.Html
@model Role

<div class="pageContent">
	@using (Html.BeginForm("Edit", "Role", FormMethod.Post, new {@class = "pageForm required-validate", onsubmit = "return validateCallback(this, navTabAjaxDone);"}))
	{
		<div class="pageFormContent" layouth="60">
			@Html.HiddenFor(model => model.FunctionCodes)
			<p class="nowrap">
				@Html.LabelFor(model => model.RoleId)
				@Html.ReadonlyFieldFor(model => model.RoleId)
			</p>
			<dl class="nowrap">
				@Html.LabelFor(model => model.RoleName)
				@Html.TextBoxFor(model => model.RoleName, new {@class = "required", minlength = "2", maxlength = "20"})
			</dl>
			<p class="nowrap">
				@Html.EnumCheckBoxList("selectedUserTypes", Html.DisplayNameFor(m => m.UserTypes).ToString(), (UserTypes) Model.UserTypes, UserTypes.Developer)
			</p>
			<p class="nowrap">
				@Html.LabelFor(model => model.Description)
				@Html.TextAreaFor(model => model.Description)
			</p>
			<p class="nowrap">
				@Html.LabelFor(model => model.FunctionCodes)
				@MenuHelper.GenerateMenu4Check(ViewBag.WebObjects, Model.FunctionCodes, "onCheckChanged")
			</p>
		</div>
		<div class="formBar">
			<ul>
				<li>
					<div class="buttonActive">
						<div class="buttonContent">
							<button type="submit">保存</button>
						</div>
					</div>
				</li>
				<li>
					<div class="button">
						<div class="buttonContent">
							<button type="button" class="close">取消</button>
						</div>
					</div>
				</li>
			</ul>
		</div>
	}
</div>
<script type="text/javascript">
	function onCheckChanged() {
		var json = arguments[0];
		var selectedIds = [];
		$(json.items).each(function() {
			selectedIds.push(this.value);
		});
		$("#FunctionCodes").val($.toJSON(selectedIds));
	}
</script>